/**
 * 
 */
package com.kandinfo.isbnmanage.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kandinfo.base.common.dto.ResultDto;
import com.kandinfo.base.common.dto.ResultDtoFactory;
import com.kandinfo.isbnmanage.dto.IsbnInformationDto;
import com.kandinfo.isbnmanage.dto.IsbnOrderDto;
import com.kandinfo.isbnmanage.service.IsbnSaveAndUpdateService;


/**
 * 
 * isbn新增更改
 * 
 * @author qiweiyang
 *
 */
@Controller
@RequestMapping(value = "/isbnSaveAndUpdate")
public class IsbnSaveAndUpdateController {
	
	private final static Logger LOG = LoggerFactory.getLogger(IsbnSaveAndUpdateController.class);
	
	@Autowired
	IsbnSaveAndUpdateService isbnSaveAndUpdateService;
  
	/**
	 * 新增和保存isbnInformation
	 * 
	 * 请注意信息完整
	 * 
	 * @param isbnInformationResDto
	 * @return
	 */
    @RequestMapping(value = "/informationSaveAndUpdate", method = RequestMethod.POST)
    @ResponseBody
    public ResultDto informationSaveAndUpdate(@RequestBody IsbnInformationDto isbnInformationResDto) {
    	try {
			return isbnSaveAndUpdateService.informationSaveAndUpdate(isbnInformationResDto);
		} catch (Exception e) {
			LOG.error("informationSaveAndUpdate ERROR!",e);
			return ResultDtoFactory.toNack(e.getMessage());
		}
    }
    
    /**
	 * 新增和保存isbnOrder
	 * 
	 * 请注意信息完整
	 * 
	 * @param isbnOrderReqDto
	 * @return
	 */
    @RequestMapping(value = "/orderSaveAndUpdate", method = RequestMethod.POST)
    @ResponseBody
    public ResultDto orderSaveAndUpdate(@RequestBody IsbnOrderDto isbnOrderReqDto) {
    	try {
			return isbnSaveAndUpdateService.orderSaveAndUpdate(isbnOrderReqDto);
		} catch (Exception e) {
			LOG.error("orderSaveAndUpdate ERROR!",e);
			return ResultDtoFactory.toNack(e.getMessage());
		}
    }
    
    /**
     * 
     * 新增和保存图片
     * 即上传图片
     * @王伟补充
     *
     * 
     * @param request
     * @param response
     * @param id				isbnInformationId  
     * @param isCover			图片类型
     * 					0 封面    1不是封面
     * @return
     */
    @RequestMapping(value = "/uploadFile/{id}/{isCover}", method = RequestMethod.POST)
    @ResponseBody
    public ResultDto addPage(HttpServletRequest request,HttpServletResponse response ,@PathVariable("id") Long id,@PathVariable("isCover") String isCover){
    	return isbnSaveAndUpdateService.uploadFile(request, response,id,isCover);
    }
    
    /**
     * 删除封面
     * @return
     */
    @RequestMapping(value = "/deleteCover/{isbnInformationId}", method = RequestMethod.POST)
    @ResponseBody
    public ResultDto deleteCover(HttpServletRequest request,HttpServletResponse response ,@PathVariable("isbnInformationId") Long isbnInformationId){
    	return isbnSaveAndUpdateService.deleteCover(isbnInformationId);
    }
    /**
     * 删除图片
     * @return
     */
    @RequestMapping(value = "/deletePage/{homeworkTemporaryId}", method = RequestMethod.POST)
    @ResponseBody
    public ResultDto deletePage(HttpServletRequest request,HttpServletResponse response ,@PathVariable("homeworkTemporaryId") Long homeworkTemporaryId){
    	return isbnSaveAndUpdateService.deletePage(homeworkTemporaryId);
    }
}
